package com.csht.service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csht.mapper.CshtCriminalRecordsMapper;
import com.csht.model.CshtCriminalRecords;
import com.csht.page.PagerModel;
import com.csht.service.CshtCriminalRecordsService;

/**
 * 违规记录Service
 * @author chenhuiyan
 *
 */
@Service
public class CshtCriminalRecordsServiceImpl implements CshtCriminalRecordsService {
	
	@Autowired
	private CshtCriminalRecordsMapper cshtCriminalRecordsMapper;

	/**
	 * 根据用户id查询违规记录总数
	 */
	@Override
	public Integer getCriminalRecordsNumberByUserId(Integer userId) throws Exception {
		Integer totalSize = cshtCriminalRecordsMapper.getCriminalRecordsNumberByUserId(userId);
		return totalSize;
	}

	/**
	 * 根据用户id查询违规记录
	 */
	@Override
	public PagerModel<CshtCriminalRecords> getCriminalRecordsByUserId(Map<String, Integer> res) throws Exception {
		List<CshtCriminalRecords> cshtCriminalRecordslist = cshtCriminalRecordsMapper.getCriminalRecordsByUserId(res);
		Integer totalSize = cshtCriminalRecordsMapper.getCriminalRecordsNumberByUserId(res.get("userId"));
		Integer offset = res.get("offset"); //获取偏移量
		Integer messagePageSize = res.get("messagePageSize"); //获取每页的数量
		PagerModel<CshtCriminalRecords> pagerModel = new PagerModel<CshtCriminalRecords>();
		pagerModel.setDates(cshtCriminalRecordslist);
		pagerModel.setMessagePageSize(messagePageSize);
		pagerModel.setOffset(offset);
		pagerModel.setTotalSize(totalSize);
		return pagerModel;
	}

	/**
	 * 根据违规记录id查询
	 */
	@Override
	public CshtCriminalRecords getCriminalRecordsById(Integer criminalRecordsId) throws Exception {
		CshtCriminalRecords cshtCriminalRecords = cshtCriminalRecordsMapper.getCriminalRecordsById(criminalRecordsId);
		return cshtCriminalRecords;
	}

	/**
	 * 根据用户id查询非常严重违规次数
	 */
	@Override
	public Integer getLevelTimesByUserId(Integer userId) throws Exception {
		Integer levelTimes = cshtCriminalRecordsMapper.getLevelTimesByUserId(userId);
		return levelTimes;
	}

}
